package sample3.grammar;

import org.antlr.runtime.ANTLRStringStream;
import org.antlr.runtime.CharStream;
import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.RecognitionException;
import org.antlr.runtime.TokenStream;

import sample3.evaluators.Evaluator;
import sample3.gen.Sample3Lexer;
import sample3.gen.Sample3Parser;
import sample3.visitor.EvalVisitor;
import sample3.visitor.PrintVisitor;

public class Test3 {

	public static void main(String[] args) throws RecognitionException {
		CharStream charStream = new ANTLRStringStream("3/2/3+0+9");
		Sample3Lexer lexer  = new Sample3Lexer(charStream);
		TokenStream tockenStream = new CommonTokenStream(lexer);
		Sample3Parser parser = new Sample3Parser(tockenStream ); 
		;
		Evaluator evaluator = parser.evaluator();
		System.out.println("done! " + evaluator.evaluate());
		System.out.println(evaluator.toTreeString(""));
		EvalVisitor visitor = new EvalVisitor();
		PrintVisitor visitor2 = new PrintVisitor();
		evaluator.accept(visitor);
		evaluator.accept(visitor2);
//		System.out.println("vis val " + visitor.getEvaluation());
		System.out.println("" + visitor2.getOut());
	}
}
